<?php
set_time_limit(0);
if (isset($_POST['uid']) && isset($_POST['n'])){
    include '../c/config.php';
    //$openid=trim($_POST['op']);
    $uid=$_POST['uid'];
    $name=addslashes(trim($_POST['n']));
    $phone=addslashes(trim($_POST['ph']));
    $email=addslashes(trim($_POST['email']));
    $idcard=addslashes(trim($_POST['idc']));
    $nianji=$_POST['nianji'];
    $qu=addslashes(trim($_POST['qu']));
    $hui=addslashes(trim($_POST['hui']));
    $school=addslashes(trim($_POST['school']));
    $school2=addslashes(trim($_POST['school2']));
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}
    
    if (5 == $nianji) {
       $queryJ=$mysqli->query("SELECT id from `u5` where uid='".$uid."' and phone='".$phone."' limit 0,1 ");
    }elseif (4 == $nianji) {
       $queryJ=$mysqli->query("SELECT id from `u4` where uid='".$uid."' and phone='".$phone."' limit 0,1 ");	
    }else{
       $queryJ=$mysqli->query("SELECT id from `u3` where uid='".$uid."' and phone='".$phone."' limit 0,1 ");
    }	

    if($queryJ->num_rows>0){

    }else{
        $mysqli->query("INSERT INTO `uinfo` (`id`, `uid`, `name`,`phone`,`email`,`idcard`,`nianji`,`qu`,`hui`,`school`,`school2`,`createtime`) VALUES (NULL,'".$uid."', '".$name."','".$phone."','".$email."','".$idcard."', '".$nianji."','".$qu."','".$hui."','".$school."','".$school2."', '".date("Y-m-d H:i:s")."')");


        if (5 == $nianji) {
        	 $mysqli->query("INSERT INTO `u5` (`id`, `uid`, `phone`,`createtime`) VALUES (NULL,'".$uid."', '".$phone."', '".date("Y-m-d H:i:s")."')");
        }elseif (4 == $nianji) {
        	 $mysqli->query("INSERT INTO `u4` (`id`, `uid`, `phone`,`createtime`) VALUES (NULL,'".$uid."', '".$phone."', '".date("Y-m-d H:i:s")."')");
        }else{
            $mysqli->query("INSERT INTO `u3` (`id`, `uid`, `phone`,`createtime`) VALUES (NULL,'".$uid."', '".$phone."', '".date("Y-m-d H:i:s")."')");
        }

    }

    $mysqli->query("INSERT INTO `u_log` (`id`, `uid`, `name`,`phone`,`email`,`idcard`,`nianji`,`qu`,`hui`,`school`,`school2`,`createtime`) VALUES (NULL,'".$uid."', '".$name."','".$phone."','".$email."','".$idcard."', '".$nianji."','".$qu."','".$hui."','".$school."','".$school2."', '".date("Y-m-d H:i:s")."')");

    
    $mysqli->close();
    echo json_encode(array('s'=>'y'));
}else{
    echo json_encode(array('s'=>'n'));
}

?>